package com.szh.jexcel.base;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
	@Value("${jexcel.upload.address}")
	private String address;
	@Value("${jexcel.upload.base}")
	private String base;
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// addPathPatterns 用于添加拦截规则
		// excludePathPatterns 用户排除拦截
		registry.addInterceptor(new MyHttpInterceptor()).addPathPatterns("/**")
			.excludePathPatterns("/static/**",base+"/**");
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		//需要配置1：----------- 需要告知系统，这是要被当成静态文件的！
		//第一个方法设置访问路径前缀，第二个方法设置资源路径
		registry.addResourceHandler(base+"/**").addResourceLocations("file:"+address);
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		
	}
	
}
